
{include file="public/head" /}
    

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="ibox float-e-margins">
                <div class="ibox-title">学生信息</div>
                <div class="ibox-content">
                    <div class="row">
                        <!--搜索框开始-->
                        <div class="col-sm-12">
                            <div class="layui-form layui-form-item">
                                <!--搜索框开始-->
                                <div class="col-sm-12">
                                    <div class="layui-form layui-form-item">
                                        <div class="layui-input-inline layui-form">
                                            <input type="text" id="keyword" class="layui-input" name="keyword" value="" placeholder="关键字" maxlength="10" autocomplete="off" />
                                        </div>
                                        <div class="layui-input-inline layui-form">
                                            <select name="sex" lay-search="">
                                                <option value="">性别</option>
                                                <option value="1">男</option>
                                                <option value="2">女</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-inline layui-form">
                                            <select name="status" lay-search="">
                                                <option value="">状态</option>
                                                <option value="1">正常</option>
                                                <option value="2">离校</option>
                                                <option value="3">处分</option>
                                                <option value="4">异常</option>
                                                <option value="5">毕业</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table id="demo" class="layui-hide" lay-filter="test"></table>
                    <script type="text/html" id="sex">
                        {{# if(d.sex == 1){ }}
                        男
                        {{# } }}
                        {{# if(d.sex == 2){ }}
                        女
                        {{# } }}
                    </script>
                    <script type="text/html" id="status">
                        {{# if(d.status == 1){ }}
                        <button type="button" class="layui-btn layui-btn-xs">正常</button>
                        {{# } }}
                        {{# if(d.status == 2){ }}
                        <button type="button" class="layui-btn layui-btn-warm layui-btn-xs">离校</button>
                        {{# } }}
                        {{# if(d.status == 3){ }}
                        <button type="button" class="layui-btn layui-btn-danger layui-btn-xs">处分</button>
                        {{# } }}
                        {{# if(d.status == 4){ }}
                        <button type="button" class="layui-btn layui-btn-danger layui-btn-xs">异常</button>
                        {{# } }}
                        {{# if(d.status == 5){ }}
                        <button type="button" class="layui-btn layui-btn-normal layui-btn-xs">毕业</button>
                        {{# } }}
                    </script>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                    <script>
                        layui.use('table', function(){
                            var table = layui.table
                                , form = layui.form;
                            //第一个实例
                            table.render({
                                elem: '#demo'
                                //,height: 312
                                ,url: "{:url('teacher/student/index')}" //数据接口
                                ,page: true //开启分页
                                ,response: {
                                    statusCode: 200 //成功的状态码，默认：0
                                }
                                , size: 'lg' //sm小尺寸的表格 lg大尺寸
                                , cellMinWidth: 150
                                , limits: [5, 10, 15, 20, 25, 30]
                                , limit: "{:config('pages')}"
                                , toolbar: '#toolbarDemo'
                                , defaultToolbar: ['filter','print', 'exports'] //工具类
                                , loading: true
                                , id: 'test'
                                ,cols: [[ //表头
                                    {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
                                    ,{field: 's_name', title: '姓名-点击姓名修改',width:180,sort:true,edit: 'text'}
                                    ,{field: 'sex', title: '性别',width:100,templet:"#sex"}
                                    ,{field: 'class_id', title: '班级号',event:"class_info"}
                                    ,{field: 'status', title: '状态',templet:"#status"}
                                    ,{field: 'create_time', title: '创建时间',id: '#time'}
                                    ,{fixed: 'right', width:100, title: '操作', align: 'center', toolbar: '#barDemo'}
                                ]]
                            });
                            //监听搜索
                            form.on('submit(LAY-search)', function (data) {
                                //执行重载
                                table.reload('test', {
                                    page: {
                                        curr: 1 //重新从第 1 页开始
                                    }
                                    ,where: data.field
                                });
                            });
                            //监听单元格编辑
                            table.on('edit(test)', function(obj){
                                var value = obj.value //得到修改后的值
                                    ,data = obj.data //得到所在行所有键值
                                    ,field = obj.field; //得到字段
                                // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
                                $.ajax({
                                    url:"{:url('teacher/student/change_name')}",
                                    type:'post',
                                    dataType:'json',
                                    data:{"id":data.id,"value":value,"field":field},
                                    success:function(res){
                                        if (res.data == 1) {
                                            layer.msg(res.message);
                                        } else if (res.data == 0) {
                                            layer.msg(res.message);
                                        } else {
                                            layer.msg("出现未知错误，修改失败");
                                        }
                                    },error:function () {
                                        layer.msg("出现未知错误，修改失败");
                                    }
                                })
                            });
                            table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                                var data = obj.data; //获得当前行数据
                                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

                                if(layEvent === 'class_info'){ //查看
                                    $.ajax({
                                        url:"{:url('teacher/student/class_info_alert')}",
                                        type:'post',
                                        dataType:'json',
                                        data:{"class_id":data.class_id},
                                        success:function(res){
                                            console.log(res);
                                        },error:function () {
                                            layer.msg("出现未知错误，修改失败");
                                        }
                                    })
                                }
                            });
                        });
                    </script>
                </div>
            </div>
        </div>
    </div>
<!-- 全局js -->
    {include file="public/footer" /}
</body>
</html>
